<template>
  <div>
    <el-table :data="tableData" :show-header="false" style="width: 100%;margin-top: 15px;" height="100" :header-cell-style="headerCellStyle" :cell-style="cellStyle">
      <template slot="empty">
        <p>暂无推屏</p>
      </template>
      <el-table-column prop="sort" align="center" label="序号" min-width="10%">
      </el-table-column>
      <el-table-column prop="image" :show-overflow-tooltip="true" align="center" label="商品图片" min-width="20%">
        <template slot-scope="scope">
          <img :src="scope.row.productPhoto" width="64" height="64">
        </template>
      </el-table-column>
      <el-table-column prop="productName" :show-overflow-tooltip="true" align="center" label="商品名称" min-width="30%">
      </el-table-column>
      <el-table-column prop="price" :show-overflow-tooltip="true" align="center" label="商品价格" min-width="10%">
      </el-table-column>
      <el-table-column prop="clickNum" :show-overflow-tooltip="true" align="center" label="点击次数" min-width="10%">
      </el-table-column>
      <el-table-column prop="pushNum" :show-overflow-tooltip="true" align="center" label="推送次数" min-width="10%">
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="25%">
        <template slot-scope="scope">
          <el-button type="text" disabled size="mini" v-if="scope.row.isTop">{{scope.row.countdown>0?scope.row.countdown+'s':'推送中'}}</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
  export default {
    name: "liveControllerShopPushScreen",
    components: {
    },
    props:{
      data:{
        type: Object,
        default:()=>{}
      }
    },
    data() {
      return {
        headerCellStyle:{
          'background-color': '#f1f1f1',
          'font-size':'12px',
          'color':'#000000'
        },
        cellStyle:{
          'font-size':'12px',
          'border-bottom':'0'
        },
        tableData:[],
        timer: null
      }
    },
    mounted: function () {
      this.parentData = this.data
      if(this.parentData){
        this.getData()
        this.startTimer()
      }
    },
    destroyed(){ // 页面销毁
      this.clearTimer()
    },
    methods: {
      init(data){
        this.parentData = data
        this.getData()
        this.startTimer()
      },
      startTimer(){ // 定时器
        let i=0;
        this.timer = setInterval(() => {
          this.tableData.forEach((item,idx) => {
            if(item.isTop==1 && item.countdown>0){
              item.countdown = item.countdown - 1 <= 0 ? 0 : item.countdown - 1;
            } else if(item.isTop==1 && item.countdown == 0){
              this.getData();
            }
          })
          if(i==5){
            this.getData();
            i=0;
          }
          i++;
        },1000)
      },
      clearTimer(){ // 清除定时器
        clearInterval(this.timer)
      },
      pushScreen(row){
        this.getData();
      },
      getData(){
        this.utils.request.liveRequest({
          url: '/api/v1/liveProductInfo/push/'+this.parentData.id,
          method: 'get'
        }).then(result => {
          let data = result.data;
          if (data && data.code == '0') {
            this.tableData = data.data;
          }
        })
      }
    }
  }
</script>
<style scoped lang="scss">

</style>
